package com.aioething.iot.controller;

import cn.hutool.core.util.IdUtil;
import com.aioething.iot.dto.OtaTaskDto;
import com.aioething.iot.model.OtaTask;
import com.aioething.iot.service.IOtaTaskService;
import com.aioething.iot.vo.OtaTaskVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Date;

@RequestMapping("ota")
@RestController
public class OtaTaskController {
    @Autowired
    private IOtaTaskService otaTaskService;

    @GetMapping
    public PageInfo<OtaTaskVo> query(OtaTaskDto otaTaskDto) {
        return otaTaskService.query(otaTaskDto);
    }

    @PutMapping
    public void create(@RequestBody OtaTask otaTask) throws IOException {
        otaTask.setTaskId(IdUtil.fastSimpleUUID());
        otaTask.setCreateTime(new Date());
        otaTaskService.create(otaTask);
    }

    @DeleteMapping
    public int delete(@RequestParam String taskId) {
        return otaTaskService.delete(taskId);
    }
}
